#@head() #@header()
<title>客户列表</title>
#@aside("user")
<script type="text/javascript" src="#(path)/assets/js/jquery.tmpl.min.js"></script>
<style>
	.box-body{padding:5px !important}
</style>
<div class="content-wrapper">
	<section class="content">
	<div class="nav-tabs-custom">
		#@usermenu("tzjl")

		<div class="tab-content">
		  <div class="tab-pane active" id="tab_1">
			<div class="box-body">
             
				<label style="float:left;margin-top:8px;margin-left:10px;">交易名称：</label>
                <input id="jyname" type="text" style="width:120px;float:left" class="form-control" placeholder="">

				<label style="float:left;margin-top:8px;margin-left:5px;">时间区间：</label>
				<input id="sjstart" style="width:120px;float:left" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="text" class="form-control" placeholder="">
				<label style="float:left;margin-top:8px;">—</label>
                <input id="sjend" style="width:120px;float:left" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="text" class="form-control" placeholder="">
                
				
				<label style="float:left;margin-top:8px;margin-left:5px;">放款时间：</label>
                <input id="fkstart" style="width:120px;float:left" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="text" class="form-control" placeholder="">
				<label style="float:left;margin-top:8px;">—</label>
                <input id="fkend" style="width:120px;float:left" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="text" class="form-control" placeholder="">
             
				
				<label style="float:left;margin-top:8px;margin-left:5px;">还款时间：</label>
                <input id="hkstart" id="fkstart" style="width:120px;float:left" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="text" class="form-control" placeholder="">
				<label style="float:left;margin-top:8px;">—</label>
                <input id="hkend" id="fkstart" style="width:120px;float:left" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="text" class="form-control" placeholder="">
				
				<label style="float:left;margin-top:8px;margin-left:5px;">交易状态：</label>
				<select id="jyzt" style="width:120px;float:left" class="form-control">
					<option value="">全部</option>
					<option value="success">交易结束</option>
					<option value="closed">超时关闭</option>
					<option value="paid">已付款</option>
					<option value="process">付款中</option>
					<option value="failed">付款失败</option>
				</select>
				
				<div class="col-xs-1">
				  <button id="seachuser" type="button" class="btn btn-info btn-flat">搜索</button>
				</div>

            </div>

			<div class="box-body">
				<table  id="example1" class="table table-striped">
					<thead>
						<tr>
							<th>交易流水号</th>
							<th>投资时间</th>
							<th>交易名称</th>
							<th>投资金额</th>
							
							<th>所用优惠券</th>
							<th>还款时间</th>
							<th>状态</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody id="userlist">
						
					</tbody>
				</table>
				<div class="box-footer clearfix">
				  <ul class="pagination pagination-sm no-margin pull-right">
					<li id="userlist1"><a href="#">首页</a></li>
					<li id="userlist2"><a href="#">上一页</a></li>
					<li><a href="#">第<span id="userlist5"></span>页 共<span id="userlist6"></span>页</a></li>
					<li id="userlist3"><a href="#">下一页</a></li>
					<li id="userlist4"><a href="#">尾页</a></li>
				  </ul>
				</div>
			</div>
			</div>
		</div>
	</div>
	</section>
</div>
#@footer()
<script id="userlistall" type="text/x-jquery-tmpl">
	<tr>
		<td>${code}</td>
		<td>${create_time}</td>
		<td>${bidname}</td>
		<td>${amount}元</td>
		<td>${youhui}</td>
		<td>${target_time}</td>
		<td>${status}</td>
		<td>
			<button onclick="window.open('#(path)/admin/page/enclosure-printht?id=${bid_id}&userId=${userid}&amount=${amount}')" type="button" class="btn btn-success">电子合同</button>
		</td>
		
	</tr>
</script>
<script>
 $(document).ready(function(){

	var totalPage = 1;
	var pageNumber = 1;
	var url = "";
	pageNumber = 1;
	$("#userlist").empty();
	url = "#(path)/trade/list?token=#(session.token??)&page=1&size=15&userId="+id.id;
	userlist(url);
	$("#userlist5").html(pageNumber);
	
	$("#userlist1").click(function(){
		$("#userlist").empty();
		url = "#(path)/trade/list?token=#(session.token??)&page=1&size=15&userId="+id.id;
		userlist(url);
		$("#userlist5").html(pageNumber);
	});
	$("#userlist2").click(function(){
		if(pageNumber==1){
			alert("当前页是首页!");
		}else{
		$("#userlist").empty();
		pageNumber = pageNumber-1;
		url = "#(path)/trade/list?token=#(session.token??)&page="+pageNumber+"&size=15&userId="+id.id;
		userlist(url);
		$("#userlist5").html(pageNumber);
		}
	});
	$("#userlist3").click(function(){
		if(pageNumber==totalPage){
			alert("当前页是尾页!");
		}else{
		$("#userlist").empty();
		pageNumber = pageNumber +1;
		url = "#(path)/trade/list?token=#(session.token??)&page="+pageNumber+"&size=15&userId="+id.id;
		userlist(url);
		$("#userlist5").html(pageNumber);
		}
	});
	$("#userlist4").click(function(){
		$("#userlist").empty();
		url = "#(path)/trade/list?token=#(session.token??)&page="+totalPage+"&size=15&userId="+id.id;
		userlist(url);
		pageNumber = totalPage;
		$("#userlist5").html(pageNumber);
	});
	$("#seachuser").click(function(){
		$("#userlist").empty();
		var jyname = $("#jyname").val();
		var sjstart = $("#sjstart").val();
		var sjend = $("#sjend").val();
		var fkstart = $("#fkstart").val();
		var fkend = $("#fkend").val();
		var hkstart = $("#hkstart").val();
		var hkend = $("#hkend").val();
		var jyzt = $("#jyzt").val();
		url = "#(path)/trade/list?token=#(session.token??)&page=1&size=15&bidName="+jyname+"&createTimeStart="+sjstart+"&createTimeEnd="+sjend+"&applyTimeStart="+fkstart+"&applyTimeEnd="+fkend+"&targetTimeStart="+hkstart+"&targetTimeEnd="+hkend+"&status="+jyzt+"&userId="+id.id;
		 
		userlist(url);
		pageNumber = 1;
		$("#userlist5").html(pageNumber);
	});

	function userlist(url){
		$.getJSON(url, function(userli) {
			 
			totalPage = userli.data.page.totalPage;
			$("#userlist6").html(totalPage);
			$.each(userli.data.page.list, function(i, item){ 
				var userid = item.user.id;
				var youhui = "";
				if(!$.isBlank(item.tzhb)){
					youhui += "投资红包："+item.tzhb.amount+" 元 ";
				}
				if(!$.isBlank(item.tyj)){
					youhui += "体验金："+item.tyj.amount+" 元 ";
				}
				if(!$.isBlank(item.jxq)){
					youhui += "加息券："+item.jxq.amount +" % ";
				}
				 
				if(item.status == "success"){var status = "交易结束"}
					else if(item.status == "closed"){var status = "超时关闭"}
					else if(item.status == "paid"){var status = "已付款 "}
					else if(item.status == "process"){var status = "付款中 "}
					else if(item.status == "failed"){var status = "付款失败 "}
				var userlist = {userid:userid,bid_id:item.bid_id,youhui:youhui,bidname:item.bid_name,status:status,target_time:item.target_time,code:item.code,create_time:item.create_time,mobile:item.mobile,amount:item.amount};
				$("#userlistall").tmpl(userlist).appendTo('#userlist');
			});
		});	
	}
});

</script>
</body>
</html>